﻿@model IOA.MES.DataAccess.VModel.VWorkorderLable
@{
    ViewBag.Title = "标签设置";
    Layout = "~/Views/Shared/_LayoutPage.cshtml";
    var tamplates = ViewBag.Templates as List<IOA.MES.DataAccess.VModel.VLabelTemplate>;
}

<div id="page"></div>

<script type="text/template" id="tplPage">
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body layui-form">
                <div class="layui-form-item">
                    <label class="layui-form-label">{{lang.Field.TemplateSelection}}</label>
                    <div class="layui-input-inline">
                        <select id="selTemplates" lay-filter="selTemplates" name="TemplateId" lay-search="">
                            <option value="">选择标签模板</option>
                            @foreach (var item in tamplates)
                            {
                                <option value="@item.PkId" @((Model?.TemplateId ?? 0) == item.PkId ? " selected " : "")>@item.TemplateName</option>
                            }
                        </select>
                    </div>
                    <input type="hidden" name="OrderNo" value="@ViewBag.OrderNo" />
                    <input type="hidden" name="WorkOrderNo" value="@ViewBag.WorkOrderNo" />
                    <button class="layui-btn layuiadmin-btn-list layui-btn-normal" lay-submit lay-filter="submit">
                        <i class="layui-icon layui-icon-ok layuiadmin-button-btn"></i>{{lang.Field.Submit}}
                    </button>
                    <button class="layui-btn layui-btn-normal" id="btnMgr">{{lang.Field.TemplateManagement}}</button>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">{{lang.Field.SerialNumber}}</label>
                    <div class="layui-input-inline">
                        <input type="text" name="SerialNum" readonly autocomplete="off" class="layui-input" value="@(Model==null?string.Empty:Model.SerialNum)">
                    </div>
                    <a class="layui-btn layuiadmin-btn-list layui-btn-normal" target="_blank" href="/Common/Download?url=@(HttpUtility.UrlEncode(Model?.SerialNum))"><i class="layui-icon">&#xe601;</i></a>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">{{lang.Field.BorderBarCode}}</label>
                    <div class="layui-input-inline">
                        <input type="text" name="BorderBarCode" readonly autocomplete="off" class="layui-input" value="@(Model==null?string.Empty:Model.BorderBarCode)">
                    </div>
                    <a class="layui-btn layuiadmin-btn-list layui-btn-normal" target="_blank" href="/Common/Download?url=@(HttpUtility.UrlEncode(Model?.BorderBarCode))"><i class="layui-icon">&#xe601;</i></a>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">{{lang.Field.Nameplate}}</label>
                    <div class="layui-input-inline">
                        <input type="text" name="Nameplate" readonly autocomplete="off" class="layui-input" value="@(Model==null?string.Empty:Model.Nameplate)">
                    </div>
                    <a class="layui-btn layuiadmin-btn-list layui-btn-normal" target="_blank" href="/Common/Download?url=@(HttpUtility.UrlEncode(Model?.Nameplate))"><i class="layui-icon">&#xe601;</i></a>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">{{lang.Field.CurrentLabel}}</label>
                    <div class="layui-input-inline">
                        <input type="text" name="CurrentTag" readonly autocomplete="off" class="layui-input" value="@(Model==null?string.Empty:Model.CurrentTag)">
                    </div>
                    <a class="layui-btn layuiadmin-btn-list layui-btn-normal" target="_blank" href="/Common/Download?url=@(HttpUtility.UrlEncode(Model?.CurrentTag))"><i class="layui-icon">&#xe601;</i></a>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">{{lang.Field.EnergyLabel}}</label>
                    <div class="layui-input-inline">
                        <input type="text" name="EnergyTag" readonly autocomplete="off" class="layui-input" value="@(Model==null?string.Empty:Model.EnergyTag)">
                    </div>
                    <a class="layui-btn layuiadmin-btn-list layui-btn-normal" target="_blank" href="/Common/Download?url=@(HttpUtility.UrlEncode(Model?.EnergyTag))"><i class="layui-icon">&#xe601;</i></a>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">{{lang.Field.Mark}}</label>
                    <div class="layui-input-inline">
                        <input type="text" name="Mark" readonly autocomplete="off" class="layui-input" value="@(Model==null?string.Empty:Model.Mark)">
                    </div>
                    <a class="layui-btn layuiadmin-btn-list layui-btn-normal" target="_blank" href="/Common/Download?url=@(HttpUtility.UrlEncode(Model?.Mark))"><i class="layui-icon">&#xe601;</i></a>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">{{lang.Field.PackNoLabel}}</label>
                    <div class="layui-input-inline">
                        <input type="text" name="PallNumTag" readonly autocomplete="off" class="layui-input" value="@(Model==null?string.Empty:Model.PallNumTag)">
                    </div>
                    <a class="layui-btn layuiadmin-btn-list layui-btn-normal" target="_blank" href="/Common/Download?url=@(HttpUtility.UrlEncode(Model?.PallNumTag))"><i class="layui-icon">&#xe601;</i></a>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">{{lang.Field.FRReport}}</label>
                    <div class="layui-input-inline">
                        <input type="text" name="FrChart" readonly autocomplete="off" class="layui-input" value="@(Model==null?string.Empty:Model.FrChart)">
                    </div>
                    <a class="layui-btn layuiadmin-btn-list layui-btn-normal" target="_blank" href="/Common/Download?url=@(HttpUtility.UrlEncode(Model?.FrChart))"><i class="layui-icon">&#xe601;</i></a>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">{{lang.Field.ObaData}}</label>
                    <div class="layui-input-inline">
                        <input type="text" name="OBAData" readonly autocomplete="off" class="layui-input" value="@(Model==null?string.Empty:Model.OBAData)">
                    </div>
                    <a class="layui-btn layuiadmin-btn-list layui-btn-normal" target="_blank" href="/Common/Download?url=@(HttpUtility.UrlEncode(Model?.OBAData))"><i class="layui-icon">&#xe601;</i></a>
                </div>
            </div>
        </div>
    </div>
</script>

@section Scripts{
    <script>
        var vm = new Vue({
            el: "#page",
            template: "#tplPage",
            data: {
                lang: JSON.parse(lang).package
            }
        });
        setTimeout(function () {
            initLayui();
        }, 50);
        function initLayui() {
            layui.use(['form', 'layer', 'upload'], function () {
                var layer = layui.layer,
                    upload = layui.upload,
                    form = layui.form;

                form.on('select(selTemplates)', function (data) {
                    var templateId = $("#selTemplates").val() == "" ? 0 : parseInt($("#selTemplates").val());
                    if (templateId <= 0) {
                        return;
                    }
                    var loadId = layer.load();
                    $.ajax({
                        url: "/ParaSetting/GetLabelTemplate",
                        data: {
                            templateId: templateId
                        },
                        complete: function () {
                            layer.close(loadId);
                        },
                        success: function (res) {
                            if (res.ErrCode != 200) {
                                layer.msg(res.ErrMsg, { icon: 5 });
                                return;
                            }
                            for (var item in res.Data) {
                                var dom = $("input[name=" + item + "]");
                                if (dom.length > 0) {
                                    dom.val(res.Data[item]);
                                }
                            }
                        }
                    });
                    return false;
                });

                $(document).on("click", ".btnDel", function () {
                    $("input[name=" + $(this).attr("name") + "]").val("");
                });

                $(document).on("click", "#btnMgr", function () {
                    parent.parent.layui.index.openTabsPage("/ParaSetting/LabelTemplateMgr", "标签模板");
                });

                form.on('submit(submit)', function (data) {
                    console.log(data.field);
                    var loadId = layer.load();
                    $.ajax({
                        url: "/ParaSetting/EditLable",
                        data: {
                            model: data.field
                        },
                        complete: function () {
                            layer.close(loadId);
                        },
                        success: function (res) {
                            if (res.ErrCode != 200) {
                                layer.msg(res.ErrMsg, { icon: 5 });
                                return;
                            }
                            layer.msg("保存成功！", { icon: 6, time: 1500 });
                        }
                    });
                    return false;
                });
            });
        }
    </script>
}
